﻿/***
 * 
 *    Title: "ZGUIFW"UI框架项目
 *           主题： 语言国际化      
 *    Description: 
 *           功能： 根据不同的id来读取不同的文字
 *    Date: 2018
 *    Version: 0.1版本
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ZGUIFW
{
	public class LanguageMgr
    {
        private static LanguageMgr _instance;
        private Dictionary<string, string> _dicLanguageCache;
        private LanguageMgr()
        {
            _dicLanguageCache = new Dictionary<string, string>();
			InitLanguageCache();
        }
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <returns>The instance.</returns>
        public static LanguageMgr GetInstance()
        {
            return _instance ?? (_instance = new LanguageMgr());
        }

        public string ShowText(string key)
		{
			if (string.IsNullOrEmpty(key)) return null;
			if (_dicLanguageCache == null || _dicLanguageCache.Count == 0) return null;
			string value = string.Empty;
			_dicLanguageCache.TryGetValue(key, out value);
			if (string.IsNullOrEmpty(value))
			{
				Debug.LogError("can't find language made key: " + key);
				return null;	
			} 
			return value;
		}

        private void InitLanguageCache()
        {
			IConfigMgr configMgr = new ConfigMgrByJson("LauguageJSONConfig");
			if (configMgr == null)
			{
				Debug.Log("con't find LauguageJSONConfig json");
				return;
			}
			_dicLanguageCache = configMgr.AppSetting;
        }

    }
}


